<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang='zh-CN' xml:lang='zh-CN' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Content-Language" content="zh-CN"/>
<meta name="robots" content="index, follow" />
<title>抽奖程序</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script src="js/wind-core.js"></script>
<script src="js/wind-compiler.js"></script>
<script src="js/wind-builderbase.js"></script>
<script src="js/wind-async.js"></script>
<style>
* {font-size:16pt;font-weight:bold; font-family:"Microsoft YaHei",sans-serif;}
body {margin: 5px;}
form {margin:12px 0 20px 0;}
input {text-align:center;}
a {font-size:16pt;}
</style>
</head>
<body background="bg.jpg" >
<CENTER> 
<form id='lottery_form' >
抽取 <input type='text' id='c_count' name='count' value='5' size='4'/> 名幸运员工
<input type='button' id='btn_begin1' value='开始抽奖1' onclick='begin_chose1()'/>
<input type='button' id='btn_begin2' value='开始抽奖2' onclick='begin_chose2()'/>
<input type='button' id='btn_begin3' value='开始抽奖3' onclick='begin_chose3()'/>
<input type='button' id='btn_begin4' value='开始抽奖4' onclick='begin_chose4()'/>
<input type='button' id='btn_begin' value='查看奖品' onclick='show_result();'/>
</form>
<form id='showluck1'>
获奖号码
</form>
<form id='showluck3'>

</form>
<form>
参奖号码（字体最大的是被选中的号码，未显示的号码为已经中奖号码。）
</form>
<form id='showluck4'>

</form>

</CENTER>
<canvas id="myCanvas">Fallback content, in case the browser does not support Canvas.</canvas>
</body>

<script type='text/javascript'>
var PERSON_COUNT = 211; //抽奖参加人数（每个人一个号码）
var brick_width = 40;   //每个抽奖号码的宽度；
var brick_height = 22;  //每个抽奖号码的高度；
var col_count = 0;      //抽奖号码列数计数；
//var results=new Array(); //抽中号码数组；
var canvas = document.getElementById('myCanvas');  
var ctx = canvas.getContext('2d');
var sound1,sound2,sound3;
var arr = [13, 158, 176, 157, 103, 113, 108, 6, 195, 162,136];  //已经抽中的号码
//var ctx1 = canvas.getContext('2d');    //
var c_count=0;   
var results1=new Array(); //抽中号码数组；

var x_choose=0;
var y_choose=0;

resize_canvas();  //canvas 区域大小定义；
//draw_bricks();
re_draw_bricks();  //重画抽奖号码；
//load_songs();

//showcanvas();

function showcanvas(){
	var cWidth = 640;
	var cHeight = 60;
    ctx1.fillStyle="#fff";    	 
	ctx1.fillRect(10, 25, cWidth, cHeight);	
}

function resize_canvas(){
	var cWidth = document.body.clientWidth - 210;
	var cHeight = (PERSON_COUNT / (cWidth / (brick_width+10))) * (brick_height+10) + 150;
    if (canvas.width  < cWidth)
        canvas.width  = cWidth;    
    if (canvas.height < cHeight)
        canvas.height = cHeight;   
	
}

//function load_songs(){
//	sound1 = new Audio("e.wav");
//	sound1.load();
//	sound2 = new Audio("e2.wav");
//	sound2.load();
//	sound3 = new Audio("e3.wav");
//	sound3.load();
//}


//重画抽奖号码canvas区域
function re_draw_bricks(){
	var x = 210,y = 20;
	var tmp_c_count = 0;

	
	for(c = 0; c < PERSON_COUNT; c++){
	    
		if (jQuery.inArray(c+1, arr)>=0 ){
           ctx.fillStyle="#a90909";
		   ctx.font="1px Microsoft YaHei";
	       ctx.strokeText(c+1,x+10,y+brick_height-7);		
    	}else{
		   if (jQuery.inArray(c+1, results1)>=0 ){
			   ctx.fillStyle="#a90909";
			   ctx.font="24px Microsoft YaHei";
			   ctx.fill();
			   ctx.strokeText(c+1,x+10,y+brick_height-7);
		   }else{
           ctx.fillStyle="#40AA53";
		   ctx.font="12px Microsoft YaHei";
	       ctx.strokeText(c+1,x+10,y+brick_height-7);
		   }
		}
		
		 
		x += (brick_width + 10);
		tmp_c_count ++;
		if((x + brick_width) > 1024){
			y += (brick_height + 10);
			x = 210;
			if(col_count == 0)
				col_count = tmp_c_count;
		}
		
		
	}
	
}

//抽奖开始1
function begin_chose1(){
	$('#btn_begin1').attr('disabled',true);
	var nc = parseInt($('#c_count').val());

    showAsync(nc).addEventListener("success", function () {
		//sound3.play();
        //$('#btn_begin').removeAttr("disabled");	
		//$('#lottery_form').append("<input type='button' value='查看中奖名单' onclick='show_result();'/>");
    }).start();
	
}

//抽奖开始2
function begin_chose2(){
	$('#btn_begin2').attr('disabled',true);
	var nc = parseInt($('#c_count').val());

    showAsync(nc).addEventListener("success", function () {
		//sound3.play();
        //$('#btn_begin').removeAttr("disabled");	
		//$('#lottery_form').append("<input type='button' value='查看中奖名单' onclick='show_result();'/>");
    }).start();
	
}


//随机数测试函数
function luckRandom(){
    var last = -1;
	var r;
	var nc = parseInt($('#c_count').val());

	for(oc=0;oc<nc;oc++){
		r = Math.floor(Math.random() * PERSON_COUNT) + 1;//0-PERSON_COUNT		
	
        if (jQuery.inArray(r, arr)>=0 ){
			oc = oc - 1;
			continue;
		}
		if(jQuery.inArray(r, results1)>=0){
			oc = oc - 1;
			continue;
		}
		results1.push(r);
        $('#showluck3').append("<a>["+ r + ",oc=" + oc + "，]</a>");
	}


};


//单个随机数测试函数
function singleluckRandom(){
    var r;
	c_count = c_count + 1;
	for(oc=0;oc<1;oc++){
		r = Math.floor(Math.random() * PERSON_COUNT) + 1;//0-PERSON_COUNT		
	
        if (jQuery.inArray(r, arr)>=0 ){
			oc = oc - 1;
			continue;
		}
		if(jQuery.inArray(r, results1)>=0){
			oc = oc - 1;
			continue;
		}
		results1.push(r);
        //$('#showluck3').append("<a>["+ r + ",num=" + c_count + "，]</a>");
	}

    //$await(Wind.Async.sleep(100));
};


//抽中号码逐个显示函数
var showdrawAsync = eval(Wind.compile("async", function (ccount) {

    var r;
	c_count = c_count + 1;
	for(oc=0;oc<1;oc++){
		r = Math.floor(Math.random() * PERSON_COUNT) + 1;//0-PERSON_COUNT		
	
        if (jQuery.inArray(r, arr)>=0 ){
			oc = oc - 1;
			continue;
		}
		if(jQuery.inArray(r, results1)>=0){
			oc = oc - 1;
			continue;
		}
		results1.push(r);
        $('#showluck3').append("<a>"+ r + ", </a>");
	}
	$await(Wind.Async.sleep(300));
	//return 0;
}));


var shownumdrawAsync = eval(Wind.compile("async", function (ccount) {

    var r;

	r = Math.floor(Math.random() * PERSON_COUNT) + 1;

	if (jQuery.inArray(r, arr)>=0 ){
	   return 0;
	}
	if(jQuery.inArray(r, results1)>=0){
	    return 0 ;
	}
	$('#showluck4').append("<a>["+ r + "] </a>");

	//$await(Wind.Async.sleep(10));
	//return 0;
}));


//动态抽奖显示函数
var shownumdrawAsync2 = eval(Wind.compile("async", function (ccount) {

    var r;
	var x = 210,y = 20;
	var tmp_c_count = 0;
	
	//r = Math.floor(Math.random() * PERSON_COUNT) + 1;

	var c=document.getElementById("myCanvas");
	var ctx=c.getContext("2d");
    
	ctx.clearRect(x,y-20,1024,640);

    for(c = 0; c < PERSON_COUNT; c++){
	    
		r = Math.floor(Math.random() * PERSON_COUNT) + 1;
		
		var x1 = ((r - 1) % col_count) * (brick_width + 10) + 210;
		var y1 = (Math.ceil(r / col_count)-1) * (brick_height + 10) +20;
		

		ctx.font="0px Microsoft YaHei";
		ctx.strokeText(r-1,x1+10,y1+brick_height-7);
		
		ctx.font="12px Microsoft YaHei";
		ctx.strokeText(r-1,x1+10,y1+brick_height-7);		

		if (r-1 != c+1){
		  ctx.strokeText(c+1,x+10,y+brick_height-7);
		}
				
		//ctx.clearRect(r,x+10,y+brick_height-7);
        //$('#showluck2').append("<a>["+ r + "] </a>");

		//ctx.font="18px Microsoft YaHei";
	    //ctx.strokeText(c+1,x+10,y+brick_height-7);
		 
		x += (brick_width + 10);
		tmp_c_count ++;
		if((x + brick_width) > 1024){
			y += (brick_height + 10);
			x = 210;
			if(col_count == 0)
				col_count = tmp_c_count;
		}
				
	}


}));

//动态抽奖号码重画
var shownumdrawAsync6 = eval(Wind.compile("async", function (ccount) {

    var r;
	var x = 210,y = 20;
	var tmp_c_count = 0;
	
	//r = Math.floor(Math.random() * PERSON_COUNT) + 1;

	var c=document.getElementById("myCanvas");
	var ctx=c.getContext("2d");
    
	ctx.clearRect(x,y-20,1024,640);

    for(c = 0; c < PERSON_COUNT; c++){
	    
		//r = Math.floor(Math.random() * PERSON_COUNT) + 1;
		
		//ctx.font="32px Microsoft YaHei";
	    //ctx.strokeText(r,x+10,y+brick_height-7);
		
		if (jQuery.inArray(c+1, arr)>=0 ){
           ctx.fillStyle="#a90909";
		   ctx.font="1px Microsoft YaHei";
	       ctx.strokeText(c+1,x+10,y+brick_height-7);		
    	}else{
		   if (jQuery.inArray(c+1, results1)>=0 ){
			   ctx.fillStyle="#a90909";
			   ctx.font="24px Microsoft YaHei";
			   ctx.fill();
			   ctx.strokeText(c+1,x+10,y+brick_height-7);
		   }else{
           ctx.fillStyle="#40AA53";
		   ctx.font="9px Microsoft YaHei";
	       ctx.strokeText(c+1,x+10,y+brick_height-7);
		   }
		}
				 
		x += (brick_width + 10);
		tmp_c_count ++;
		if((x + brick_width) > 1024){
			y += (brick_height + 10);
			x = 210;
			if(col_count == 0)
				col_count = tmp_c_count;
		}
		
		
	}
}));


//动态按时间抽取随机数
var showAsync = eval(Wind.compile("async", function(num_count){
	
	
	do{
		
		$await(showdrawAsync(20)); //选中的随机号码
		$await(shownumdrawAsync2(30)); //动态抽奖显示
		if(results1.length >= num_count){
		  break;
		}
		
	}while(true);
    
	$await(shownumdrawAsync6(10)); //重画抽奖最终结果；
}));



function show_result(){
	var args = "";
	for(oc=0;oc<results1.length;oc++){
		args += results1[oc];
		args += ',';
	}
	open("show.html?nums=" + args + "&num1=88888,99999");
}
</script>
</html>